﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.Security;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for NonSecuredBaseView
/// </summary>
public class NonSecuredBaseView : Page
{
    private TemplateControl contolPage = null;
    public NonSecuredBaseView()
    {
        contolPage = this;
    }
    public NonSecuredBaseView(TemplateControl view)
    {
        contolPage = view;
    }
    public int? UserID
    {
        get
        {
            if (Session[SessionLiterals.UserID] == null)
            {
                return null;
            }
            else
            {
                return int.Parse(Session[SessionLiterals.UserID].ToString());
            }
        }
        set
        {
            Session[SessionLiterals.UserID] = value;
        }
    }
    public string UserName
    {
        get
        {
            if (Session[SessionLiterals.UserName] == null)
            {
                return null;
            }
            else
            {
                return Session[SessionLiterals.UserName].ToString();
            }
        }
        set
        {
            Session[SessionLiterals.UserName] = value;
        }
    }
    public int? CompanyID
    {
        get
        {
            if (Session[SessionLiterals.CompanyID] == null)
            {
                return null;
            }
            else
            {
                return int.Parse(Session[SessionLiterals.CompanyID].ToString());
            }
        }
        set
        {
            Session[SessionLiterals.CompanyID] = value;
        }
    }
    public string ImageName
    {
        get
        {
            if (Session[SessionLiterals.ImageName] == null)
            {
                return null;
            }
            else
            {
                return Session[SessionLiterals.ImageName].ToString();
            }
        }
        set
        {
            Session[SessionLiterals.ImageName] = value;
        }
    }

    private HtmlGenericControl ErrorDiv
    {
        get
        {
            HtmlGenericControl error = contolPage.FindControl("diverror") as HtmlGenericControl;
            if (error != null)
                return error;
            else
                return null;
        }
    }
    private HtmlGenericControl SuccessDiv
    {
        get
        {
            HtmlGenericControl success = contolPage.FindControl("divsuccess") as HtmlGenericControl;
            if (success != null)
                return success;
            else
                return null;
        }
    }
    public string ErrorMessage
    {
        set
        {
            if (value.Trim() == string.Empty)
            {
                ErrorDiv.Style.Add("display", "none");
            }
            else
            {
                ErrorDiv.Style.Remove("display");
                ErrorDiv.InnerHtml = value;
                SuccessMessage = string.Empty;
            }
        }
    }
    public string ExceptionMessage
    {
        set
        {
            if (value.Trim() == string.Empty)
            {
                ErrorDiv.Style.Add("display", "none");
            }
            else
            {
                ErrorDiv.Style.Remove("display");
                ErrorDiv.InnerHtml = "The server has encountered the following error(s): </br></br>" + value;
                SuccessMessage = string.Empty;
            }
        }
    }
    public string SuccessMessage
    {
        set
        {
            if (value.Trim() == string.Empty)
            {
                SuccessDiv.Style.Add("display", "none");
            }
            else
            {
                SuccessDiv.Style.Remove("display");
                SuccessDiv.InnerHtml = value;
                ErrorMessage = string.Empty;
            }
        }
    }
    public void ClearMessage()
    {
        ErrorMessage = string.Empty;
        SuccessMessage = string.Empty;
    }
}